package com.android.flowoflife.hardware;

import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.ShutterCallback;

public class CameraAccess extends AbstractCameraAccess {
	private Camera camera;
	
	public CameraAccess(int width, int height) {
		super(width, height);
	}
	
	@Override
	public boolean lock() {
		if (camera != null)
			return true;
		camera = Camera.open();
		if (camera == null)
			return false;
		Camera.Parameters params = camera.getParameters();
		params.setPictureSize(width, height);
		params.setPictureFormat(PixelFormat.RGB_565);
		camera.setParameters(params);
		
		return true;
	}
	
	@Override
	public void release() {
		if (camera != null) {
			camera.release();
			camera = null;
		}
	}

	@Override
	public void takePicture(ShutterCallback shutterCallback, PictureCallback rawPictureCallback, PictureCallback jpegPictureCallback) {
		if (camera != null) {
			camera.takePicture(shutterCallback, rawPictureCallback, jpegPictureCallback);
		}
	}

}
